home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / a_utils / expanded.lha / test_suite / testmap.C < prev    next >
C/C++ Source or Header  |  1992-03-19  |  18KB  |  690 lines

  1. //
  2. // Linear-Affine-Projective Geometry Package
  3. //
  4. // testmap.C
  5. //
  6. // $Header$
  7. //
  8. // William J.R. Longabaugh 
  9. // University of Washington
  10. //
  11. // Test programs for the linear-affine-projective geometry
  12. // package described in William J.R. Longabaugh, "An Expanded
  13. // System for Coordinate-Free Geometric Programming", Master's 
  14. // thesis, University of Washington, 1992.
  15. //
  16. // Copyright (c) 1992, William J.R. Longabaugh
  17. //   Copying, use and development for non-commercial purposes permitted.
  18. //   All rights for commercial use reserved.
  19. //   This software is unsupported and without warranty; it is
  20. //   provided "as is".
  21. //
  22. // ***********************************************************************
  23.  
  24. #include "Lap.h"
  25. #include <math.h>
  26.  
  27. extern void test1(void);
  28. extern void test2(void);
  29. extern void test3(void);
  30. extern void test4(void);
  31. extern void test5(void);
  32. extern void test6(void);
  33. extern void test7(void);
  34. extern void test8(void);
  35. extern void test9(void);
  36. extern void test10(void);
  37.  
  38. // ***********************************************************************
  39.  
  40. int main(void)
  41. {
  42.   test1();
  43.   test2();
  44.   test3();
  45.   test4();
  46.   test5();
  47.   test6();
  48.   test7();
  49.   test8();
  50.   test9();
  51.   test10();
  52.  
  53.   return (0);
  54. }
  55.  
  56.  
  57. // ***********************************************************************
  58. // Test the casting of multimaps and geobs to maps:
  59.  
  60. void test1(void)
  61. {
  62.   cout << "ENTERING TEST1\n";
  63.   VSpace v("Test vector space", 3, TRUE);
  64.   ASpace a("Test affine space", 2, TRUE);
  65.   PSpace p("Test projective space", v, a);
  66.  
  67. // Create a first order map and convert it to a Multimap.  Use this
  68. // multimap to convert back to a map:
  69.  
  70.   Frame fra = a.StdBasis();
  71.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  72.   APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
  73.   APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
  74.  
  75.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  76.   Simplex std = a.StdSimplex(); 
  77.   AffineMap am(std, s1);
  78.  
  79.   MAM multi(am);
  80.  
  81.   AffineMap newmap(multi);
  82.  
  83.   GeOb hold = am(std[1]);
  84.   cout << hold;
  85.   hold = multi(std[1]);
  86.   cout << hold;
  87.   hold = newmap(std[1]);
  88.   cout << hold;
  89.  
  90. // Fully evaluate the multimap and convert to a map to the reals
  91. // (Domain space will be the dual of the linearization):
  92.  
  93.   MAM noargp;
  94.   noargp = multi(GeObList(fra[2]));
  95.   LinearMap newmapl = noargp;
  96.   Vector lin = a3;
  97.   Vector lind = lin.Dual();
  98.  
  99.   Scalar output = newmapl(lind).ToScalar();
  100.   cout << "\n result = "<< output << "\n";
  101.  
  102. // Cast a geob to a map:
  103.  
  104.   PPoint pp1(a1);
  105.   newmapl = pp1;
  106.   output = newmapl(lind).ToScalar();
  107.   cout << "\n result = "<< output << "\n";
  108. }
  109.  
  110. // ***********************************************************************
  111. // Tests of map application, obtaining associated linear:
  112.  
  113. void test2(void)
  114. {
  115.   cout << "ENTERING TEST2\n";
  116.  
  117.   VSpace v("Test vector space", 3, TRUE);
  118.   ASpace a("Test affine space", 2, TRUE);
  119.   PSpace p("Test projective space", v, a);
  120.  
  121. // Create an affine map:
  122.  
  123.   Frame fra = a.StdBasis();
  124.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  125.   APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
  126.   APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
  127.   APoint a4(fra, ScalarList(-1.4, -7.9, 1.0));
  128.   Vector zv(v.StdBasis(), ScalarList(0.0, 0.0, 0.0));
  129.  
  130.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  131.   Simplex std = a.StdSimplex();
  132.   AffineMap am(s1, std);
  133.  
  134.   GeOb ar = am(a2);
  135.   cout << ar;
  136.  
  137.   GeOb arv = am(a1 - a3);
  138.   cout << arv;
  139.  
  140.   LinearMap almp = am.AssocLinear();
  141.   
  142.   arv = almp(a1 - a2);
  143.   cout << arv;
  144.  
  145. // Affine map to linear subset:
  146.  
  147.   VSubSet targ("target subset", v, GeObList(a1, a2));
  148.   AffineMap aml(a.StdSimplex(), targ, GeObList(a1, zv, a2));
  149.   VBasis vb = v.StdBasis();
  150.  
  151.   GeOb res = aml(std[2]);
  152.   cout << res;
  153.  
  154.   res = aml(std[0] - std[2]);
  155.   cout << res;
  156.  
  157.   almp = aml.AssocLinear();
  158.   
  159.   res = almp(std[0] - std[2]);
  160.   cout << res;
  161.  
  162. // Affine map from projective space:
  163.  
  164.   AffineMap apm(p.StdAffineSubset(), GeObList(a1, a2, a3), a.StdSimplex());
  165. // g++ problem again:
  166. // PPoint pp1 = (5.0 * a1.MapTo(VECTOR)).MapTo(VEC_EC).MapTo(PROJ_POINT);
  167.  
  168.   GeOb hold = a1.MapTo(VECTOR);
  169.   hold = 5.0 * hold;
  170.   hold = hold.MapTo(VEC_EC);
  171.   GeOb pp1 = hold.MapTo(PROJ_POINT);
  172.   ar = apm(pp1);
  173.   cout << ar;
  174. }
  175.  
  176. // ***********************************************************************
  177. // Tests inverting, transpose:
  178.  
  179. void test3(void)
  180. {
  181.   cout << "ENTERING TEST3\n";
  182.   VSpace v("Test vector space", 3, TRUE);
  183.   ASpace a("Test affine space", 2, TRUE);
  184.   PSpace p("Test projective space", v, a);
  185.  
  186. // Create an affine map, invert it:
  187.  
  188.   Frame fra = a.StdBasis();
  189.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  190.   APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
  191.   APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
  192.   APoint a4(fra, ScalarList(-1.4, -7.9, 1.0));
  193.  
  194.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  195.   Simplex std = a.StdSimplex();
  196.   AffineMap am(std, s1);
  197.  
  198.   GeOb apt = am(std[1]);
  199.   cout << apt;
  200.  
  201.   am = am.Inv();
  202.   apt = am(apt);
  203.   cout << apt;
  204.  
  205. // Create a linear map, take the transpose:
  206.  
  207.   Basis bas = v.StdBasis();
  208.   Vector v1(bas, ScalarList(3.6, -4.5, 2.4));
  209.   Vector v2(bas, ScalarList(2.2, 5.1, -3.2));
  210.   Vector v3(bas, ScalarList(-6.7, 2.3, 1.0));
  211.   Vector v4(bas, ScalarList(-1.4, -7.9, 8.2));
  212.  
  213.   VBasis b1("test basis", v, GeObList(v1, v2, v3));
  214.   LinearMap lm(b1, bas);
  215.   Vector v2d = v2.Dual();
  216.  
  217.   Scalar output = v2d.Apply(v4);
  218.   cout << "\n result = "<< output << "\n";
  219.  
  220.   Vector res = lm(v4);
  221.  
  222.   lm = lm.Trans().Inv();
  223.  
  224.   Vector resd = lm(v2d);
  225.  
  226.   output = resd.Apply(res);
  227.   cout << "\n result = "<< output << "\n";
  228. }
  229.  
  230. // ***********************************************************************
  231. // Induced maps:
  232.  
  233. void test4(void)
  234. {
  235.   cout << "ENTERING TEST4\n";
  236.   VSpace v("Test vector space", 3, TRUE);
  237.   ASpace a("Test affine space", 2, TRUE);
  238.   ASpace as2("Test affine space 2", 2, TRUE);
  239.   PSpace p("Test projective space", v, a);
  240.  
  241. // Build an affine map:
  242.  
  243.   Frame fra = a.StdBasis();
  244.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  245.   APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
  246.   APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
  247.  
  248.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  249.   AffineMap am(s1, as2.StdSimplex());
  250.   
  251.   GeOb resa = am(a2);
  252.   cout << resa;
  253.  
  254.   PPoint pp2 = a2;
  255.   Vector v2 = a2;
  256.  
  257.   ProjectiveMap ip = am.InducedProjective();
  258.   LinearMap il = am.InducedLinear();
  259.  
  260.   GeOb res = il(v2);
  261.   cout << res;
  262.  
  263.   GeOb resp = ip(pp2);
  264.   cout << resp;
  265. }
  266.  
  267. // ***********************************************************************
  268. // Composition:
  269.  
  270. void test5(void)
  271. {
  272.   cout << "ENTERING TEST5\n";
  273.   VSpace v("Test vector space", 3, TRUE);
  274.   ASpace a("Test affine space", 2, TRUE);
  275.   ASpace as2("Test affine space 2", 2, TRUE);
  276.   PSpace p("Test projective space", v, a);
  277.  
  278. // Build affine maps:
  279.  
  280.   Frame fra = a.StdBasis();
  281.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  282.   APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
  283.   APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
  284.  
  285.   Simplex as2std = as2.StdSimplex();
  286.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  287.   AffineMap am(as2std, s1);
  288.  
  289.   Simplex s2("test simplex2", a, GeObList(a3, a1, a2));
  290.   AffineMap am2(s2, as2std);
  291.  
  292. // Build a projective map:
  293.  
  294.   HFrame hfra = p.StdBasis();
  295.   PPoint p1(hfra, ScalarList(2.1, 3.6, -4.5));
  296.   PPoint p2(hfra, ScalarList(2.5, 7.8, 6.2));
  297.   PPoint p3(hfra, ScalarList(-3.4, 2.8, 4.4));
  298.   PPoint p4(hfra, ScalarList(-8.8, 3.9, -2.2));
  299.  
  300.   HFrame hf1("test hframe", p, GeObList(p1, p2, p3, p4));
  301.   ProjectiveMap pm(p.StdBasis(), hf1);
  302.  
  303. // Compose:
  304.  
  305.   AffineMap amc = am2.Compose(am);
  306.   GeOb resa = am2(am(as2std[2]));
  307.   cout << resa;
  308.   resa = amc(as2std[2]);
  309.   cout << resa;
  310.  
  311.   ProjectiveMap pmc = pm.ComposeProj(am);
  312.   GeOb resp = pm(am(as2std[2]));
  313.   cout << resp;
  314.   resa = pmc(as2std[2]);
  315.   cout << resp;
  316. }
  317.  
  318. // ***********************************************************************
  319. // Affine functionals:
  320.  
  321. void test6(void)
  322. {
  323.   cout << "ENTERING TEST6\n";
  324.   VSpace v("Test vector space", 3, TRUE);
  325.   ASpace a("Test affine space", 2, TRUE);
  326.   PSpace p("Test projective space", v, a);
  327.  
  328.   Frame fra = a.StdBasis();
  329.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  330.   APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
  331.   APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
  332.  
  333.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  334.   AffineMap am(s1, Reals.FullSet(), GeObList(3.4, 1.2, 5.6));
  335.  
  336.   Scalar output = am(a2).ToScalar();
  337.   cout << "\n result = "<< output << "\n";
  338.  
  339.   output = am(a3).ToScalar();
  340.   cout << "\n result = "<< output << "\n";
  341.  
  342.   output = am(a2 - a3).ToScalar();
  343.   cout << "\n result = "<< output << "\n";
  344.  
  345.   Vector adv = am.AssocDualVector();
  346.   output = adv.Apply(a2 - a3);
  347.   cout << "\n result = "<< output << "\n";
  348. }
  349.  
  350. // ***********************************************************************
  351. // Tests of various linear map constructors:
  352.  
  353. void test7(void)
  354. {
  355.   cout << "ENTERING TEST7\n";
  356.   VSpace v("Test vector space", 3, TRUE);
  357.   VSpace vs2("Test vector space 2", 4, TRUE);
  358.   ASpace a("Test affine space", 2, TRUE);
  359.   PSpace p("Test projective space", v, a);
  360.  
  361. // Build bases, linear subsets:
  362.  
  363.   VBasis bas = v.StdBasis();
  364.   APoint a1(a.StdBasis(), ScalarList(3.6, -4.5, 1.0));
  365.   Vector v1 = a1;
  366.   Vector v2(bas, ScalarList(2.5, 7.8, -2.4));
  367.   Vector v3(bas, ScalarList(-3.4, 2.8, 5.6));
  368.   VBasis b1("test basis", v, GeObList(v1, v2, v3));
  369.  
  370.   Vector v4(bas, ScalarList(3.1, -6.5, 9.8));
  371.   Vector v5(bas, ScalarList(1.2, -3.4, -5.8));
  372.   Vector v6(bas, ScalarList(4.6, -6.4, 5.6));
  373.   VBasis b2("test basis 2", v, GeObList(v4, v5, v6));
  374.  
  375.   VBasis bas2 = vs2.StdBasis();
  376.   Vector v7(bas2, ScalarList(2.2, 6.7, 3.1, 9.9));
  377.   Vector v8(bas2, ScalarList(-1.2, 2.7, 7.8, 5.6));
  378.   Vector v9(bas2, ScalarList(0.9, 4.6, 1.4, 5.1));
  379.   Vector v10(bas2, ScalarList(6.8, -2.9, 5.2, 5.6));
  380.   VBasis b3("test basis 3", vs2, GeObList(v7, v8, v9, v10));
  381.  
  382.   VSubSet sub1("subset 1", v, GeObList(v1, v3));
  383.   VSubSet sub2("subset 2", v, GeObList(v2, v3));
  384.   VSubSet sub3("subset 3", vs2, GeObList(v7, v8));
  385.   VSubSet sub4("subset 4", vs2, GeObList(v9, v7, v8));
  386.  
  387.   LinearMap lm1(b1, b2);
  388.   GeOb vout = lm1(v2);
  389.   cout << vout;
  390.   vout = lm1(v2 + v3);
  391.   cout << vout;
  392.  
  393.   LinearMap lm2(b1, sub4, GeObList(v9, v7, v8));
  394.   vout = lm2(v2);
  395.   cout << vout;
  396.   vout = lm2(v2 + v3);
  397.   cout << vout;
  398.  
  399.   LinearMap lm3(b1, sub4, GeObList(v9, v7, v9));
  400.   vout = lm3(v2);
  401.   cout << vout;
  402.   vout = lm3(v2 + v3);
  403.   cout << vout;
  404.  
  405.   LinearMap lm4(sub4, GeObList(v8, v9, v7), b2);
  406.   vout = lm4(v8);
  407.   cout << vout;
  408.   vout = lm4(v8 + v7);
  409.   cout << vout;
  410.  
  411.   LinearMap lm5(sub3, GeObList(v8 + v7, v7), sub1, GeObList(a1, v1 + v3));
  412.   vout = lm5(v7);
  413.   cout << vout;
  414.   vout = lm5(v8 + v7);
  415.   cout << vout;
  416. }
  417.  
  418. // ***********************************************************************
  419. // Tests of various affine map constructors:
  420.  
  421. void test8(void)
  422. {
  423.   cout << "ENTERING TEST8\n";
  424.   VSpace v("Test vector space", 3, TRUE);
  425.   ASpace a("Test affine space", 2, TRUE);
  426.   ASpace as2("Test affine space 2", 3, TRUE);
  427.   PSpace p("Test projective space", v, a);
  428.  
  429. // Build simplices, affine subsets:
  430.  
  431.   Simplex smp = a.StdSimplex();
  432.   Frame fra = a.StdBasis();
  433.  
  434.   APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
  435.   Vector v1 = a1;
  436.   APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
  437.   APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
  438.   Simplex s1("test simplex", a, GeObList(a1, a2, a3));
  439.  
  440.   APoint a4(fra, ScalarList(3.1, -6.5, 1.0));
  441.   APoint a5(fra, ScalarList(1.2, -3.4, 1.0));
  442.   APoint a6(fra, ScalarList(4.6, 6.4, 1.0));
  443.   Simplex s2("test simplex 2", a, GeObList(a4, a5, a6));
  444.  
  445.   Frame fra2 = as2.StdBasis();
  446.   APoint a7(fra2, ScalarList(2.2, 6.7, 9.9, 1.0));
  447.   APoint a8(fra2, ScalarList(-1.2, 7.8, 5.6, 1.0));
  448.   APoint a9(fra2, ScalarList(4.6, 1.4, 5.1, 1.0));
  449.   APoint a10(fra2, ScalarList(6.8, -2.9, 5.6, 1.0));
  450.   Simplex s3("test simplex 3", as2, GeObList(a7, a8, a9, a10));
  451.  
  452.   VBasis bas = v.StdBasis();
  453.   Vector v2(bas, ScalarList(2.5, 7.8, -2.4));
  454.   Vector v3(bas, ScalarList(2.9, -3.4, 5.6));
  455.   VSubSet vsub1("vec subset 1", v, GeObList(v2, v3));
  456.  
  457.   ASubSet sub1("subset 1", a, GeObList(a1, a3));
  458.   ASubSet sub2("subset 2", a, GeObList(a2, a3));
  459.   ASubSet sub3("subset 3", as2, GeObList(a7, a8));
  460.   ASubSet sub4("subset 4", as2, GeObList(a9, a7, a8));
  461.   ASubSet sub5("subset 5", v, GeObList(a2, a3));
  462.  
  463.   ASubSet sub6("subset 6", p, a2, GeObList(AVectorEC(a2 - a3)));
  464.  
  465.   AffineMap am1(s1, s2);
  466.   GeOb aout = am1(a2);
  467.   cout << aout;
  468.   aout = am1((a2 + a3) / 2);
  469.   cout << aout;
  470.  
  471.   AffineMap am2(s1, sub4, GeObList(a9, a7, a8));
  472.   aout = am2(a2);
  473.   cout << aout;
  474.   aout = am2((a2 + a3) / 2);
  475.   cout << aout;
  476.  
  477.   AffineMap am3(s1, sub4, GeObList(a9, a7, a9));
  478.   aout = am3(a2);
  479.   cout << aout;
  480.   aout = am3((a2 + a3) / 2);
  481.   cout << aout;
  482.  
  483.   AffineMap am4(s1, vsub1, GeObList(v2, v3, v2 + (3.0 * v3)));
  484.   aout = am4(a2);
  485.   cout << aout;
  486.   aout = am4((a2 + a3) / 2);
  487.   cout << aout;
  488.  
  489.   AffineMap am5(sub4, GeObList(a8, a9, a7), s2);
  490.   aout = am5(a9);
  491.   cout << aout;
  492.   aout = am5((a7 + a8) / 2);
  493.   cout << aout;
  494.  
  495.   AffineMap am6(sub1, GeObList(a1, a3), sub5, GeObList(a2, (a2+a3)/ 2.0));
  496.   aout = am6(a1);
  497.   cout << aout;
  498.   aout = am6((a1 + a3) / 2);
  499.   cout << aout;
  500.  
  501.   AffineMap am7(sub6, GeObList((a2 + a3)/2.0, a2), sub5, GeObList(a2, a3));
  502.   aout = am7(a2);
  503.   cout << aout;
  504.   aout = am7((a2 + a3) / 2);
  505.   cout << aout;
  506.  
  507.   AffineMap am8(sub6, GeObList(a2, a3), sub1, GeObList(v1, a3));
  508.   aout = am8(a2);
  509.   cout << aout;
  510.   aout = am8((a2 + a3) / 2);
  511.   cout << aout;
  512. }
  513.  
  514. // ***********************************************************************
  515. // Tests of various projective map constructors:
  516.  
  517. void test9(void)
  518. {
  519.   cout << "ENTERING TEST9\n";
  520.   VSpace v("Test vector space", 4, TRUE);
  521.   ASpace a("Test affine space", 3, TRUE);
  522.   PSpace p("Test projective space", v, a);
  523.   PSpace ps2("Test proj space 2", 2);
  524.   VSpace t = a.GetSpace(TANGENT);
  525.  
  526. // Build bases, projective subsets:
  527.  
  528.   HFrame hfra = p.StdBasis();
  529.   PPoint p1(hfra, ScalarList(2.2, 6.7, 3.1, 9.9));
  530.   PPoint p2(hfra, ScalarList(-1.2, 2.7, 7.8, 5.6));
  531.   PPoint p3(hfra, ScalarList(0.9, 4.6, 1.4, 5.1));
  532.   PPoint unit123(hfra, ScalarList(1.9, 14.0, 12.3, 20.6));
  533.   PPoint p4(hfra, ScalarList(6.8, -2.9, 5.2, 5.6));
  534.   PPoint unit234(hfra, ScalarList(6.5, 4.4, 14.4, 16.3));
  535.   PPoint p5(hfra, ScalarList(7.8, 3.2, -5.6, 9.3));
  536.   HFrame f1("test hframe 1", p, GeObList(p1, p2, p3, p4) + GeObList(p5));
  537.  
  538.   ProjectiveMap pm1(f1, hfra);
  539.   GeOb pout = pm1(p2);
  540.   cout << pout;
  541.   pout = pm1(p5);
  542.   cout << pout;
  543.  
  544.   PSubSet ps("regular 2d psubset", p, GeObList(p1, p2, p3));
  545.   PSubSet psr("removed psubset", p, GeObList(p1), GeObList(p2, p3, p4));
  546.  
  547.   VBasis bas = v.StdBasis();
  548.   Vector v1(bas, ScalarList(-2.5, 3.9, -9.7, 8.7));
  549.   Vector v2(bas, ScalarList(2.5, 7.8, -2.4, 1.6));
  550.   Vector v3(bas, ScalarList(-3.4, 2.8, 5.6, 7.4));
  551.   Vector v4(bas, ScalarList(3.1, -6.5, 9.8, -6.5));
  552.   Vector v5(bas, ScalarList(1.2, -3.4, -5.8, 2.8));
  553.  
  554.   PSubSet psl("psubset in v", v, GeObList(v1, v2, v3));
  555.   PSubSet pslf("full psubset in v", v, GeObList(v1, v2, v3, v4));
  556.  
  557.   VBasis bast= t.StdBasis();
  558.   AVector vt1(bast, ScalarList(-2.5, 3.9, 8.7));
  559.   AVector vt2(bast, ScalarList(2.5, -2.4, 1.6));
  560.   AVector vt3(bast, ScalarList(-3.4, 2.8, 5.6));
  561.   AVector vt4(bast, ScalarList(-6.5, 9.8, -6.5));
  562.   AVector vt5(bast, ScalarList(1.2, -5.8, 2.8));
  563.  
  564.   PSubSet pst("psubset in t", t, GeObList(vt1, vt2, vt3));
  565.  
  566. // to vector space:
  567.  
  568.   ProjectiveMap pm2(f1, pslf, GeObList(v1, v2, v3, v4) + GeObList(v5));
  569.   pout = pm2(p2);
  570.   cout << pout;
  571.   pout = pm2(p5);
  572.   cout << pout;
  573.  
  574. // non-invert:
  575.  
  576.   ProjectiveMap pm3(psr, GeObList(p2, p3, p4, unit234), ps2.StdBasis());
  577.   pout = pm3(p2);
  578.   cout << pout;
  579.   pout = pm3(p4);
  580.   cout << pout;
  581.  
  582.   ProjectiveMap pm4(ps, GeObList(p1, p2, p3, unit123), ps2.StdBasis());
  583.   pout = pm4(p2);
  584.   cout << pout;
  585.   pout = pm4(unit123);
  586.   cout << pout;
  587.  
  588. // non-invert:
  589.  
  590.   ProjectiveMap pm5(psr, GeObList(p2, p3, p4, unit234),
  591.             ps, GeObList(p1, p2, p3, unit123));
  592.   pout = pm5(p2);
  593.   cout << pout;
  594.   pout = pm5(unit234);
  595.   cout << pout;
  596.  
  597. // to tangent space:
  598.  
  599.   ProjectiveMap pm6(ps, GeObList(p1, p2, p3, unit123),
  600.             pst, GeObList(vt1, vt2, vt3, vt1 + vt2 + vt3));
  601.   pout = pm6(p2);
  602.   cout << pout;
  603.   pout = pm6(unit123);
  604.   cout << pout;
  605. }
  606.  
  607. // ***********************************************************************
  608. // Composition with affine subsets of different dimensions in a 
  609. // projective space:
  610.  
  611. void test10(void)
  612. {
  613.   cout << "ENTERING TEST10\n";
  614.   VSpace v("Test vector space", 4, TRUE);
  615.   ASpace a("Test affine space", 3, TRUE);
  616.   PSpace p("Test projective space", v, a);
  617.   VSpace t = a.GetSpace(TANGENT);
  618.   Frame fra = a.StdBasis();
  619.   VBasis vbas = v.StdBasis();
  620.   HFrame hfr = p.StdBasis();
  621.   VBasis tbas = t.StdBasis();
  622.  
  623.   Vector v1(vbas, ScalarList(6.7, 3.4, 2.8, 1.2));
  624.   Vector v2(vbas, ScalarList(2.5, 5.7, 1.3, 9.5));
  625.   Vector v3(vbas, ScalarList(7.9, 3.5, 4.1, 2.7));
  626.   Vector v4(vbas, ScalarList(7.3, 4.6, 2.2, 9.3));
  627.  
  628.   APoint p1(fra, ScalarList(6.7, 3.4, 2.8, 1.0));
  629.   APoint p2(fra, ScalarList(3.6, 2.5, -2.1, 1.0));
  630.   APoint p3(fra, ScalarList(2.2, 1.9, -0.3, 1.0));
  631.   APoint p4(fra, ScalarList(2.5, 1.6, 7.4, 1.0));
  632.  
  633.   PPoint pp1(hfr, ScalarList(6.7, 3.4, 2.8, 3.4));
  634.   PPoint pp2(hfr, ScalarList(3.6, 2.5, -2.1, 3.1));
  635.   PPoint pp3(hfr, ScalarList(2.2, 1.9, -0.3, 5.1));
  636.   PPoint pp4(hfr, ScalarList(7.4, 1.0, 2.5, 1.6));
  637.  
  638.   ASubSet as1dp("as1dp", p, pp1, GeObList(pp2));
  639.   ASubSet as2dp("as2dp", p, pp1, GeObList(pp2, pp3));
  640.   ASubSet as3dp("as3dp", p, pp1, GeObList(pp2, pp3, pp4));
  641.  
  642.   ASpace ad1("ad1", 1, TRUE);
  643.   ASpace ad2("ad2", 2, TRUE);
  644.   ASpace ad3("ad3", 3, TRUE);
  645.  
  646.   AffineMap amap(ad1.StdSimplex(), as1dp,
  647.          GeObList((2.3 * pp2 - 1.3 * pp1), (.7 * pp2 + .3 * pp1)));
  648.   AffineMap amap2(as3dp,
  649.           GeObList((0.7 * pp1 - 0.8 * pp2 + 0.5 * pp3 + 0.6 * pp4),
  650.                            (1.4 * pp1 - 0.3 * pp2 - 1.6 * pp3 + 1.5 * pp4),
  651.                            (0.3 * pp1 + 0.3 * pp2 + 0.3 * pp3 + 0.1 * pp4),
  652.                            (0.4 * pp1 + 0.7 * pp2 + 0.8 * pp3 - 0.9 * pp4)),
  653.            ad3.StdSimplex());
  654.   AffineMap acomp = amap2.Compose(amap);
  655.  
  656.  
  657.   if (acomp.Invertible()) {
  658.     cout << "Failed\n";
  659.   } else {
  660.     cout << "OK\n";
  661.   }
  662.  
  663.   Simplex ad1simp = ad1.StdSimplex();
  664.   APoint test;
  665.   APoint testin = ad1simp[1];
  666.   test = amap(testin);
  667.   test = amap2(test);
  668.   cout << test;
  669.   test = acomp(testin);
  670.   cout << test;
  671.  
  672.   testin = ad1simp[0];
  673.   test = amap(testin);
  674.   test = amap2(test);
  675.   cout << test;
  676.   test = acomp(testin);
  677.   cout << test;
  678.  
  679.   testin = -0.6 * ad1simp[1] + 1.6 * ad1simp[0];
  680.   test = amap(testin);
  681.   test = amap2(test);
  682.   cout << test;
  683.   test = acomp(testin);
  684.   cout << test;
  685. }
  686. // ***********************************************************************
  687.  
  688.  
  689.  
  690.